<template>
  <div :style="newStyle">
    <span v-if="$attrs.onlyShow">{{modelValue}}</span>
    <el-input
      v-else
      v-model="formValue"
      v-bind="$attrs"
      @input="onInput"
      @blur="onBlur"
      @focus="onFocus"
      @change="onChange"
      @clear="onClear"
    >
      <template
        slot="prepend"
        v-if="$attrs.__slot__ && $attrs.__slot__.prepend"
      >{{ $attrs.__slot__.prepend }}</template>
      <template slot="append" v-if="$attrs.__slot__ && $attrs.__slot__.append">
        {{
        $attrs.__slot__.append
        }}
      </template>
    </el-input>
  </div>
</template>

<script>
import { comMixin } from "../../../utils/comMixins";
export default {
  mixins: [comMixin],
  name: "form-input",
  model: {
    prop: "value", // 绑定的值，通过父组件传递
    event: "update",
  },
  props: {
    modelValue: {
      type: [String, Number],
      default: "",
    },
  },

  computed: {
    formValue: {
      get() {
        return this.modelValue;
      },
      set(val) {
        this.$emit("update", val);
      },
    },
  },
};
</script>

<style lang="scss" scoped></style>
